import datetime
import json

from Base.DataBase import mysqldb
from Write_Report.OutReport import output_report


class beautyreport_data():
    def getdata_from_db(self):
        result = mysqldb().read_data()
        results = result[0:45]
        reportdata={}

        reportdata['testPass'] = results[0].get('success_cases')
        testResult = []
        reportdata["testResult"] = testResult

        for result in results:
            detail_info_dict = {}
            detail_info_dict['caseid'] = result.get('case_id')
            detail_info_dict['casemodule'] = result.get('case_module')
            detail_info_dict['description'] = result.get('case_desc')
            detail_info_dict['starttime'] = result.get('case_start_time')
            detail_info_dict['endtime'] = result.get('case_end_time')
            detail_info_dict['spendTime'] = result.get('case_count_time')
            detail_info_dict['author'] = result.get('opetator')
            detail_info_dict["status"] = result.get('actual_res')
            detail_info_dict['failinfo'] = result.get('failed_info')
            testResult.append(detail_info_dict)

        reportdata['testName']='WoniuBoss Test Report'
        reportdata['testAll'] = results[0].get('total_excount')
        reportdata['testFail'] = results[0].get('failed_cases')
        reportdata['beginTime'] =results[0].get('start_time')
        reportdata['totalTime'] = results[0].get('count_time')
        reportdata['testSkip'] = 0

        output_report(reportdata)

if __name__ == '__main__':
    a = beautyreport_data()
    a.getdata_from_db()